package org.grottarossa.ui.core.controls.searchuser;

import java.util.Hashtable;
import java.util.ResourceBundle;

import org.grottarossa.ui.core.ApplicationSession;
import org.grottarossa.ui.core.base.BaseFormFieldFactory;
import org.grottarossa.ui.core.components.TMSListSelect;
import org.grottarossa.ui.core.components.TMSNativeSelect;


import com.vaadin.data.Item;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.Property.ValueChangeListener;
import com.vaadin.data.util.BeanItem;
import com.vaadin.ui.Component;
import com.vaadin.ui.DefaultFieldFactory;
import com.vaadin.ui.Field;
import com.vaadin.ui.OptionGroup;

/***
 * Factory dei campi della maschera di filtraggio sulla ricerca di un utente/ruolo
 * @author Administrator
 *
 */
public class SearchUserFormFieldFactory extends BaseFormFieldFactory implements ValueChangeListener
{
	private OptionGroup m_type;
	private TMSNativeSelect m_fieldfilter;

	public SearchUserFormFieldFactory(ApplicationSession appSession, ResourceBundle localizer)
	{
		super(appSession, localizer);

		m_type = new OptionGroup();
		m_type.addItem(m_localizer.getString("form.types.users"));
		m_type.addItem(m_localizer.getString("form.types.roles"));
		m_type.addListener(this);

		m_fieldfilter = new TMSNativeSelect(m_appSession.getDataSourceProvider(), "", "");
		m_fieldfilter.addItem(localizer.getString("form.fieldfilter.loginid"));
		m_fieldfilter.addItem(localizer.getString("form.fieldfilter.displayname"));
		m_fieldfilter.addItem(localizer.getString("form.fieldfilter.firstname"));
		m_fieldfilter.addItem(localizer.getString("form.fieldfilter.lastname"));

		m_fields.put("typefilter", m_type);
		m_fields.put("fieldfilter", m_fieldfilter);
	}

	public void valueChange(ValueChangeEvent event)
	{
		boolean visible = event.getProperty().getValue().equals(m_localizer.getString("form.types.users"));
		m_fieldfilter.setVisible(visible);
	}
}
